#!/usr/bin/env python
# SpringDS v1.0 Beta 1 - a (cross-platform?) wrapper for the FRC Driver Station
# Copyright (C) 2012 River Hill HS Robotics Team (Albert H.)
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
# This is the GUI class for the SpringDS crash dialog.
# It is used by SpringDS and SpringDS Settings.
# 
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.5 (standalone edition) on Mon Mar 19 19:16:07 2012

import wx
import sys
import traceback

# begin wxGlade: extracode
# end wxGlade

try:
    from agw import hyperlink as hl
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.hyperlink as hl

#class SDSCrashFrame(wx.Frame):
class SDSCrashFrame(wx.Dialog):
    #def __init__(self, *args, **kwds):
    def __init__(self, traceback):
        # begin wxGlade: SDSCrashFrame.__init__
        #kwds["style"] = wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.SIMPLE_BORDER | wx.FRAME_NO_TASKBAR
        #wx.Frame.__init__(self, *args, **kwds)
        #wx.Frame.__init__(self, None, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.SIMPLE_BORDER | wx.FRAME_NO_TASKBAR)
        wx.Dialog.__init__(self, None, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.SIMPLE_BORDER | wx.FRAME_NO_TASKBAR)
        self.SDSCrashBasePanel = wx.Panel(self, -1)
        self.SDSCrashErrorIcon = wx.StaticBitmap(self.SDSCrashBasePanel, -1, wx.ArtProvider.GetBitmap(wx.ART_ERROR))
        self.SDSCrashHeaderLbl = wx.StaticText(self.SDSCrashBasePanel, -1, "SpringDS crashed! :(")
        self.SDSCrashMessageLbl = wx.StaticText(self.SDSCrashBasePanel, -1, "We apologize for the inconvenience.\nWe would appreciate it if you could report this problem to us.\nClick Error Report to see the error information and for more details on how to report.\nPress OK to exit.")
        self.SDSCrashErrorReportCP = wx.CollapsiblePane(self.SDSCrashBasePanel, label="Error Report")
        #self.SDSCrashErrorReportPanel = wx.Panel(self.SDSCrashBasePanel, -1)
        self.SDSCrashErrorReportPanel = self.SDSCrashErrorReportCP.GetPane()
        self.SDSCrashErrorReportLbl = wx.StaticText(self.SDSCrashErrorReportPanel, -1, "The following error occurred:")
        self.SDSCrashErrorReportTxtCtrl = wx.TextCtrl(self.SDSCrashErrorReportPanel, -1, traceback, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_WORDWRAP)
        self.SDSCrashErrorReportingInstructionsLbl = wx.StaticText(self.SDSCrashErrorReportPanel, -1, "Copy the above error message and report it here:")
        #self.SDSCrashErrorReportingURL = wx.StaticText(self.SDSCrashErrorReportPanel, -1, "URL")
        self.SDSCrashErrorReportingURL = hl.HyperLinkCtrl(self.SDSCrashErrorReportPanel, wx.ID_ANY, "http://code.google.com/p/frcbot4067/issues/entry", URL="http://code.google.com/p/frcbot4067/issues/entry")
        self.SDSCrashOKBtn = wx.Button(self.SDSCrashBasePanel, wx.ID_OK, "")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.OnOKBtnClick, self.SDSCrashOKBtn)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: SDSCrashFrame.__set_properties
        self.SetTitle("Error - SpringDS")
        _icon = wx.EmptyIcon()
        _icon.CopyFromBitmap(wx.Bitmap("SpringDSIcon.ico", wx.BITMAP_TYPE_ANY))
        #self.SetIcon(_icon)
        self.SetIcon(wx.Icon("SpringDSIcon.ico", wx.BITMAP_TYPE_ICO, 16, 16))
        self.SDSCrashHeaderLbl.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.SDSCrashErrorReportLbl.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.SDSCrashErrorReportTxtCtrl.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, ""))
        self.SDSCrashOKBtn.SetDefault()
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: SDSCrashFrame.__do_layout
        SDSCrashBaseSizer = wx.BoxSizer(wx.VERTICAL)
        SDSCrashMainSizer = wx.FlexGridSizer(3, 1, 0, 0)
        SDSCrashButtonSizer = wx.FlexGridSizer(1, 1, 0, 0)
        SDSCrashErrorReportSizer = wx.FlexGridSizer(3, 1, 0, 0)
        SDSCrashErrorReportingSizer = wx.GridSizer(2, 1, 0, 0)
        SDSCrashBitmapMessageSizer = wx.FlexGridSizer(1, 2, 0, 0)
        SDSCrashMessageSizer = wx.FlexGridSizer(2, 1, 0, 0)
        SDSCrashBitmapMessageSizer.Add(self.SDSCrashErrorIcon, 0, wx.ALL, 4)
        SDSCrashMessageSizer.Add(self.SDSCrashHeaderLbl, 0, wx.ALL, 4)
        SDSCrashMessageSizer.Add(self.SDSCrashMessageLbl, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 4)
        SDSCrashBitmapMessageSizer.Add(SDSCrashMessageSizer, 1, wx.EXPAND, 0)
        SDSCrashMainSizer.Add(SDSCrashBitmapMessageSizer, 1, wx.EXPAND, 0)
        SDSCrashErrorReportSizer.Add(self.SDSCrashErrorReportLbl, 0, wx.ALL, 4)
        SDSCrashErrorReportSizer.Add(self.SDSCrashErrorReportTxtCtrl, 0, wx.ALL | wx.EXPAND, 4)
        SDSCrashErrorReportingSizer.Add(self.SDSCrashErrorReportingInstructionsLbl, 0, wx.ALL | wx.EXPAND, 4)
        SDSCrashErrorReportingSizer.Add(self.SDSCrashErrorReportingURL, 0, wx.ALL | wx.EXPAND, 4)
        SDSCrashErrorReportSizer.Add(SDSCrashErrorReportingSizer, 1, wx.EXPAND, 0)
        self.SDSCrashErrorReportPanel.SetSizer(SDSCrashErrorReportSizer)
        SDSCrashErrorReportSizer.AddGrowableRow(1)
        SDSCrashErrorReportSizer.AddGrowableCol(0)
        #SDSCrashMainSizer.Add(self.SDSCrashErrorReportPanel, 1, wx.EXPAND, 0)
        SDSCrashMainSizer.Add(self.SDSCrashErrorReportCP, 1, wx.EXPAND, 0)
        SDSCrashButtonSizer.Add(self.SDSCrashOKBtn, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 4)
        SDSCrashButtonSizer.AddGrowableRow(0)
        SDSCrashButtonSizer.AddGrowableCol(0)
        SDSCrashMainSizer.Add(SDSCrashButtonSizer, 1, wx.EXPAND, 0)
        self.SDSCrashBasePanel.SetSizer(SDSCrashMainSizer)
        SDSCrashBaseSizer.Add(self.SDSCrashBasePanel, 1, wx.EXPAND, 0)
        self.SetSizer(SDSCrashBaseSizer)
        SDSCrashBaseSizer.Fit(self)
        self.Layout()
        self.Centre()
        # end wxGlade

    def OnOKBtnClick(self, event):  # wxGlade: SDSCrashFrame.<event_handler>
        self.Destroy()

# end of class SDSCrashFrame
if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    #SDSCrashFrameInstance = SDSCrashFrame(None, -1, traceback="")
    try:
        SDSCrashFrameInstance = SDSCrashFrame("")
    except:
        import traceback
        print "GAHAHHHHHHHHH FAILURE!!!!"
        traceback.print_exc()
        raw_input()
    app.SetTopWindow(SDSCrashFrameInstance)
    SDSCrashFrameInstance.Show()
    app.MainLoop()
